import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class ByteStreamDemo {
    public void output (String dir, String name) {
        File file = new File(dir,name);
        if(!file.exists()){
            try {
                file.createNewFile();
                FileOutputStream fos = new FileOutputStream(file);
                String str = "书山有路勤为径，学海无涯苦作舟";
                byte[] bytes = str.getBytes();
                fos.write(bytes);
                fos.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
    public void input(String dir ,String name){
        File file = new File(dir,name);
        if(file.exists()){
            byte[] bytes = new byte[(int) file.length()];
            FileInputStream fis = null;
            try {
                fis = new FileInputStream(file);
                fis.read(bytes);
                String str = new String(bytes, StandardCharsets.UTF_8);
                System.out.println(str);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }

}
